package net.peelmeagrape.hibernate;

import net.peelmeagrape.hibernate.xmlgen.XmlAttribute;
import net.peelmeagrape.hibernate.xmlgen.XmlElement;
import net.peelmeagrape.hibernate.xmlgen.AddPropertyNameAsAttribute;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;

/**
 * Mapped classes must declare the primary key column of the database table.
 * Most classes will also have a JavaBeans-style property holding the unique
 * identifier of an instance. The &lt;id> element defines the mapping from
 * that property to the primary key column.
 * <br/>
 * <br/>
 * There is an alternative {@link CompositeId} declaration to allow access to
 * legacy data with composite keys. We strongly discourage its use for anything else.
 */
@Target({METHOD,FIELD}) @Retention(RUNTIME)
@XmlElement(name="id")
@AddPropertyNameAsAttribute(name="name")
public @interface Id
{
    /**
     * Xml mapping: element-name|&#64;attribute-name|element/&#64;attribute|.
     */
    @XmlAttribute String node() default "";

    /**
     * The strategy Hibernate should use for accessing the property value. This may be one of
     * 'property', 'field', 'embedded', or the name of a subclass of {@link org.hibernate.property.PropertyAccessor}.
     */
    @XmlAttribute String access() default "property";

    /**
     * (optional - defaults to the property name): The name of the primary key column.
     */
    @XmlAttribute String column() default "";

    /**
     * (optional): A name that indicates the Hibernate type.
     */
    @XmlAttribute String type() default "";

    /**
     * Column length.
     */
    @XmlAttribute int length() default -1;

    /**
     * (optional - defaults to a "sensible" value): An identifier property value that
     * indicates that an instance is newly instantiated (unsaved), distinguishing it
     * from detached instances that were saved or loaded in a previous session.
     * This may take the values: <i>null</i>, <i>any</i>, <i>none</i>, <i>undefined</i>,
     * or any value of the property.
     */
    @XmlAttribute("unsaved-value") String unsavedValue() default "none";

    /**
     *  The optional {@link Generator} child element names a Java class used to generate
     *  unique identifiers for instances of the persistent class.
     */
    Generator[] generator() default {};
    Column[] columnMapping() default {};
}
